<?php
// Load Zend library for Localization
include_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Translate');
Zend_Loader::loadClass('Zend_Locale');
Zend_Loader::loadClass('Zend_Date');
Zend_Loader::loadClass('Zend_Currency');
//////////////detect language

if (!isset($_SESSION['lang'])) {
	//check if cookie is set then use the chosenlaguage in cookie
	//check  selected language is supported or not 	
	if (isset($_COOKIE['lang']) 
			&& isset($config['lang']['list'][$_COOKIE['lang']])) {
		$_SESSION['lang'] = $_COOKIE['lang'];			
	} else { 
		//set to default language
		$_SESSION['lang'] = $config['lang']['default'];	
	}
	
} 

//////end////////////////////
$lang = $_SESSION['lang'];

// Zend_Locale: Set to Zend_Registry to spupport the usage of application-wide locale
$locale = new Zend_Locale($lang);
Zend_Registry::set('Zend_Locale', $locale);
// Zend_Translate
$translate = null;
try {
	$translate = new Zend_Translate('gettext',
		dirname(__FILE__) . "/languages/$lang", 
		$lang,
		array('scan' => Zend_Translate::LOCALE_DIRECTORY,
			'disableNotices'=>true
		));
	
} catch (Exception $ex) {
	//if exception while loading selected lang folder
	//we load the default langugage folder.
	$translate = new Zend_Translate('gettext',
		dirname(__FILE__) . "/languages/".$config['lang']['default'], 
		$config['lang']['default'],
		array('scan' => Zend_Translate::LOCALE_DIRECTORY,
			'disableNotices'=>true
		));	
}
Zend_Registry::set('Zend_Translate', $translate);

// Zend_Date with locale in Zend_Registry
$zendDate = new Zend_Date();
Zend_Registry::set('Zend_Date', $zendDate);

// Zend_Currency with locale in Zend_Registry
$zendCurrency = new Zend_Currency();
Zend_Registry::set('Zend_Currency', $zendCurrency);
?>
